<template>
  <el-dialog
    :title="!dataForm.uid ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="榜单成员uid" prop="memberUid">
      <el-input v-model="dataForm.memberUid" placeholder="榜单成员uid"></el-input>
    </el-form-item>
    <el-form-item label="榜单成员名称" prop="memberName">
      <el-input v-model="dataForm.memberName" placeholder="榜单成员名称"></el-input>
    </el-form-item>
    <el-form-item label="省名称" prop="province">
      <el-input v-model="dataForm.province" placeholder="省名称"></el-input>
    </el-form-item>
    <el-form-item label="省code" prop="provinceCode">
      <el-input v-model="dataForm.provinceCode" placeholder="省code"></el-input>
    </el-form-item>
    <el-form-item label="市名称" prop="city">
      <el-input v-model="dataForm.city" placeholder="市名称"></el-input>
    </el-form-item>
    <el-form-item label="市code" prop="cityCode">
      <el-input v-model="dataForm.cityCode" placeholder="市code"></el-input>
    </el-form-item>
    <el-form-item label="区名称" prop="district">
      <el-input v-model="dataForm.district" placeholder="区名称"></el-input>
    </el-form-item>
    <el-form-item label="区code" prop="districtCode">
      <el-input v-model="dataForm.districtCode" placeholder="区code"></el-input>
    </el-form-item>
    <el-form-item label="经度" prop="longitude">
      <el-input v-model="dataForm.longitude" placeholder="经度"></el-input>
    </el-form-item>
    <el-form-item label="纬度" prop="latitude">
      <el-input v-model="dataForm.latitude" placeholder="纬度"></el-input>
    </el-form-item>
    <el-form-item label="地址名称" prop="address">
      <el-input v-model="dataForm.address" placeholder="地址名称"></el-input>
    </el-form-item>
    <el-form-item label="活动开始时间" prop="startTime">
      <el-input v-model="dataForm.startTime" placeholder="活动开始时间"></el-input>
    </el-form-item>
    <el-form-item label="活动结束时间" prop="endTime">
      <el-input v-model="dataForm.endTime" placeholder="活动结束时间"></el-input>
    </el-form-item>
    <el-form-item label="报名截止时间" prop="applyEndTime">
      <el-input v-model="dataForm.applyEndTime" placeholder="报名截止时间"></el-input>
    </el-form-item>
    <el-form-item label="报名费" prop="price">
      <el-input v-model="dataForm.price" placeholder="报名费"></el-input>
    </el-form-item>
    <el-form-item label="人数上限" prop="peopleNum">
      <el-input v-model="dataForm.peopleNum" placeholder="人数上限"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item label="发起人的微信号" prop="weChat">
      <el-input v-model="dataForm.weChat" placeholder="发起人的微信号"></el-input>
    </el-form-item>
    <el-form-item label="发起人的手机号" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="发起人的手机号"></el-input>
    </el-form-item>
    <el-form-item label="状态：0删除的 1激活的 2冻结的 3置顶的" prop="status">
      <el-input v-model="dataForm.status" placeholder="状态：0删除的 1激活的 2冻结的 3置顶的"></el-input>
    </el-form-item>
    <el-form-item label="创建人uid" prop="createUserUid">
      <el-input v-model="dataForm.createUserUid" placeholder="创建人uid"></el-input>
    </el-form-item>
    <el-form-item label="创建人名称" prop="createUserName">
      <el-input v-model="dataForm.createUserName" placeholder="创建人名称"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          uid: 0,
          memberUid: '',
          memberName: '',
          province: '',
          provinceCode: '',
          city: '',
          cityCode: '',
          district: '',
          districtCode: '',
          longitude: '',
          latitude: '',
          address: '',
          startTime: '',
          endTime: '',
          applyEndTime: '',
          price: '',
          peopleNum: '',
          remark: '',
          weChat: '',
          phone: '',
          status: '',
          createUserUid: '',
          createUserName: '',
          createTime: '',
          updateTime: ''
        },
        dataRule: {
          memberUid: [
            { required: true, message: '榜单成员uid不能为空', trigger: 'blur' }
          ],
          memberName: [
            { required: true, message: '榜单成员名称不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '省名称不能为空', trigger: 'blur' }
          ],
          provinceCode: [
            { required: true, message: '省code不能为空', trigger: 'blur' }
          ],
          city: [
            { required: true, message: '市名称不能为空', trigger: 'blur' }
          ],
          cityCode: [
            { required: true, message: '市code不能为空', trigger: 'blur' }
          ],
          district: [
            { required: true, message: '区名称不能为空', trigger: 'blur' }
          ],
          districtCode: [
            { required: true, message: '区code不能为空', trigger: 'blur' }
          ],
          longitude: [
            { required: true, message: '经度不能为空', trigger: 'blur' }
          ],
          latitude: [
            { required: true, message: '纬度不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '地址名称不能为空', trigger: 'blur' }
          ],
          startTime: [
            { required: true, message: '活动开始时间不能为空', trigger: 'blur' }
          ],
          endTime: [
            { required: true, message: '活动结束时间不能为空', trigger: 'blur' }
          ],
          applyEndTime: [
            { required: true, message: '报名截止时间不能为空', trigger: 'blur' }
          ],
          price: [
            { required: true, message: '报名费不能为空', trigger: 'blur' }
          ],
          peopleNum: [
            { required: true, message: '人数上限不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          weChat: [
            { required: true, message: '发起人的微信号不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '发起人的手机号不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态：0删除的 1激活的 2冻结的 3置顶的不能为空', trigger: 'blur' }
          ],
          createUserUid: [
            { required: true, message: '创建人uid不能为空', trigger: 'blur' }
          ],
          createUserName: [
            { required: true, message: '创建人名称不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.uid = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.uid) {
            this.$http({
              url: this.$http.adornUrl(`/rank/attrinfo/info/${this.dataForm.uid}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.memberUid = data.attrInfo.memberUid
                this.dataForm.memberName = data.attrInfo.memberName
                this.dataForm.province = data.attrInfo.province
                this.dataForm.provinceCode = data.attrInfo.provinceCode
                this.dataForm.city = data.attrInfo.city
                this.dataForm.cityCode = data.attrInfo.cityCode
                this.dataForm.district = data.attrInfo.district
                this.dataForm.districtCode = data.attrInfo.districtCode
                this.dataForm.longitude = data.attrInfo.longitude
                this.dataForm.latitude = data.attrInfo.latitude
                this.dataForm.address = data.attrInfo.address
                this.dataForm.startTime = data.attrInfo.startTime
                this.dataForm.endTime = data.attrInfo.endTime
                this.dataForm.applyEndTime = data.attrInfo.applyEndTime
                this.dataForm.price = data.attrInfo.price
                this.dataForm.peopleNum = data.attrInfo.peopleNum
                this.dataForm.remark = data.attrInfo.remark
                this.dataForm.weChat = data.attrInfo.weChat
                this.dataForm.phone = data.attrInfo.phone
                this.dataForm.status = data.attrInfo.status
                this.dataForm.createUserUid = data.attrInfo.createUserUid
                this.dataForm.createUserName = data.attrInfo.createUserName
                this.dataForm.createTime = data.attrInfo.createTime
                this.dataForm.updateTime = data.attrInfo.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/rank/attrinfo/${!this.dataForm.uid ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'uid': this.dataForm.uid || undefined,
                'memberUid': this.dataForm.memberUid,
                'memberName': this.dataForm.memberName,
                'province': this.dataForm.province,
                'provinceCode': this.dataForm.provinceCode,
                'city': this.dataForm.city,
                'cityCode': this.dataForm.cityCode,
                'district': this.dataForm.district,
                'districtCode': this.dataForm.districtCode,
                'longitude': this.dataForm.longitude,
                'latitude': this.dataForm.latitude,
                'address': this.dataForm.address,
                'startTime': this.dataForm.startTime,
                'endTime': this.dataForm.endTime,
                'applyEndTime': this.dataForm.applyEndTime,
                'price': this.dataForm.price,
                'peopleNum': this.dataForm.peopleNum,
                'remark': this.dataForm.remark,
                'weChat': this.dataForm.weChat,
                'phone': this.dataForm.phone,
                'status': this.dataForm.status,
                'createUserUid': this.dataForm.createUserUid,
                'createUserName': this.dataForm.createUserName,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
